package com.winxuan.channel.model.member;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;


@Entity
@Table(name="pre_role")
public class Role implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = -5270742427741571708L;
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Integer id;
	
	@Column(name = "name")
	private String name;
	
	@Column(name = "`desc`")
	private String desc;
	
	@Column(name = "enable")
	private boolean enable;
	
	@ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE},mappedBy="roles",targetEntity=com.winxuan.channel.model.member.User.class)   	
	private Set<User> users;
	
	@ManyToMany(targetEntity=com.winxuan.channel.model.member.Resource.class,cascade={CascadeType.MERGE,CascadeType.PERSIST})
    @JoinTable(name="pre_role_2_resource",joinColumns={@JoinColumn(name="role_id")},inverseJoinColumns={@JoinColumn(name="resource_id")}) 
 	private Set<Resource> resources;
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDesc() {
		return desc;
	}
	public void setDesc(String desc) {
		this.desc = desc;
	}
	public boolean isEnable() {
		return enable;
	}
	public void setEnable(boolean enable) {
		this.enable = enable;
	}
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	public Set<Resource> getResources() {
		return resources;
	}
	public void setResources(Set<Resource> resources) {
		this.resources = resources;
	}
}
